package org.example.demo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
// @Component
public class AspectDemo {

    @Pointcut("execution(* org.example.demo.controller.*.*(..))")
    public void pt() {

    }

    @Before("pt()")
    public void doBefore() {
        log.info("执行 doBefore 方法");
    }

    @After("pt()")
    public void doAfter() {
        log.info("执行 doAfter 方法");
    }

    @AfterReturning("pt()")
    public void doAfterReturning() {
        log.info("执行 doAfterReturning 方法");
    }

    @AfterThrowing("pt()")
    public void doAfterThrowing() {
        log.info("执行 doAfterThrowing 方法");
    }

    @Around("pt()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("Around 方法开始执行");
        Object result = joinPoint.proceed();
        log.info("Around 方式执行结束");
        return result;
    }

}
